package com.hellowx.qydcdev.controller;

import com.hellowx.qydcdev.annotaion.RequiredToken;
import com.hellowx.qydcdev.entity.GoodsCategory;
import com.hellowx.qydcdev.service.GoodsCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created on 2022/1/13.
 *
 * @author Hello WX
 */
@Api(tags = "商品分类模块")
@RestController
@RequestMapping("/goodsCategory")
public class GoodsCategoryController {

    @Resource
    private GoodsCategoryService goodsCategoryService;

    @ApiOperation("获取所有的商品分类")
    @GetMapping("list")
    @RequiredToken
    public ResponseEntity<List<GoodsCategory>> listGoodsCategory(HttpServletRequest request){
        List<GoodsCategory> goodsCategoryList = goodsCategoryService.selectList(request);
        return ResponseEntity.ok(goodsCategoryList);
    }

    @ApiOperation("删除不包含商品的商品分类")
    @DeleteMapping("/noGoods")
    @RequiredToken
    public ResponseEntity<String> deleteGoodsCategoryNoGoods(@RequestParam("categoryId") Long categoryId){

        String msg = goodsCategoryService.deleteNoGoods(categoryId);
        return ResponseEntity.ok(msg);
    }

    @ApiOperation("新增商品分类")
    @PostMapping("/add")
    @RequiredToken
    public ResponseEntity<String> addGoodsCategory(String name,HttpServletRequest request){
        String msg = goodsCategoryService.addCategory(name,request);
        return ResponseEntity.ok(msg);
    }
}
